﻿using System;
using System.Reflection;

namespace UtilZ.Dotnet.Ex.Communication.Net.Web
{
    /// <summary>
    /// Api参数信息
    /// </summary>
    public class ApiParameterInfo
    {
        /// <summary>
        /// 参数值来源类型
        /// </summary>
        public ApiParameterValueSourceTypes TemplateParameterType { get; private set; }

        /// <summary>
        /// 参数信息
        /// </summary>
        public ParameterInfo ParameterInfo { get; private set; }

        /// <summary>
        /// 参数值类型
        /// </summary>
        public TypeCode ParaTypeCode { get; private set; }

        /// <summary>
        /// url参数名
        /// </summary>
        public string UrlParaName { get; private set; }


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="parameterSourceType">参数值来源类型</param>
        /// <param name="parameterInfo">参数信息</param>
        public ApiParameterInfo(ApiParameterValueSourceTypes parameterSourceType, ParameterInfo parameterInfo)
        {
            this.TemplateParameterType = parameterSourceType;
            this.ParameterInfo = parameterInfo;
            this.ParaTypeCode = Type.GetTypeCode(parameterInfo.ParameterType);
        }



        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="parameterSourceType">参数值来源类型</param>
        /// <param name="urlParaName">url参数名</param>
        public void UpdateApiParameterValueSourceType(ApiParameterValueSourceTypes parameterSourceType, string urlParaName)
        {
            this.TemplateParameterType = parameterSourceType;
            this.UrlParaName = urlParaName;
        }

        /// <summary>
        /// 重写ToString
        /// </summary>
        /// <returns>String</returns>
        public override string ToString()
        {
            return $"{ParameterInfo.Name}   {TemplateParameterType.ToString()}   {ParameterInfo.Position}  {UrlParaName}   {ParameterInfo.ParameterType.FullName}";
        }
    }
}
